﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HQWeb.Resources.HotelList
{
    public partial class HotelList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //VerdictIsLogin();
            if (!IsPostBack)
            {
                BindDate();
            }
        }

        #region 翻页事件
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                //strWhere = strWhere.Replace("order by operatetime DESC", "");
                int newPageIndex = 0;

                if (-2 == e.NewPageIndex)
                { // when click the "GO" Button
                    TextBox txtNewPageIndex = null;
                    GridViewRow pagerRow = GridView1.Controls[0].Controls[GridView1.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
                    //GridViewRow pagerRow = GridView1.BottomPagerRow; //GridView较DataGrid提供了更多的API，获取分页块可以使用BottomPagerRow 或者TopPagerRow，当然还增加了HeaderRow和FooterRow
                    if (null != pagerRow)
                    {
                        txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;   // refer to the TextBox with the NewPageIndex value
                    }

                    if (null != txtNewPageIndex)
                    {
                        newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
                    }

                    newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
                    newPageIndex = newPageIndex >= GridView1.PageCount ? GridView1.PageCount - 1 : newPageIndex;
                    GridView1.PageIndex = newPageIndex;
                }
                else if (e.NewPageIndex == -1)
                {
                    newPageIndex = 0;
                    GridView1.PageIndex = 0;
                }
                else
                {  // when click the first, last, previous and next Button
                    newPageIndex = e.NewPageIndex;
                    GridView1.PageIndex = e.NewPageIndex;
                }

                // check to prevent form the NewPageIndex out of the range


                BindDate();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion

        #region 编辑删除

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int index = e.NewEditIndex;
            string strID = GridView1.DataKeys[index].Value.ToString();

            string strName = GridView1.Rows[index].Cells[1].Text;
            string strJs = string.Format(" parent.window.returnValue='{0}'; parent.window.close();", strName);
            //string strJs = "Return()";
            Universal.JS.RunJS(strJs);
        }

        #endregion

        #region
        protected void BindDate()
        {
            BLL.SysManage.T_PUB_HOTEL bll = new BLL.SysManage.T_PUB_HOTEL();
            string strNmae = this.txtName.Text.Trim();
            string flag = drop_Area.SelectedValue;
            int bid = int.Parse(Session["BRANCH_ID"].ToString());
            GridView1.DataSource = bll.GetHotelList(strNmae, bid, flag);
            GridView1.DataBind();
        }
        #endregion


        protected void tbnSearch_Click(object sender, EventArgs e)
        {
            BindDate();
        }
    }
}